// Per Frag ADS Lighting model (Phong shading) - based on: 
//    RealTime Rendering class notes (Celes, W. 2014) 
//    Mathematics for 3D Game Programming and CG, 3th (Lengyel)
//    OpenGL Super Bible 6th (Sellers, Wright, Haemel)
//    OpenGL 4.0 Shading Cookbook (Wolff)

#version 330

in VS_OUT {
   vec3 vN;
   vec3 vL;
   vec3 vH;
} fsIn;

uniform vec4 ambientColor = vec4 (0);
uniform vec4 diffuseColor = vec4 (1.0);
uniform vec4 specularColor = vec4 (1.0);
uniform float shiness = 50;
out vec4 FragColor;

void main()
{
   vec3 vN = normalize(fsIn.vN);
   vec3 vL = normalize(fsIn.vL);
   vec3 vH = normalize(fsIn.vH);
   
   float difDot = max (0.0, dot (vL, vN));
   FragColor = (difDot*diffuseColor + ambientColor)*vec4 (1.0, 0.5, 0, 1.0);
   
   vec3 vR = normalize (reflect (- vL, vN)); // Direct reflection vector: R = 2(N.L)N - L 
   float specDot = max (0.0, dot (vN, vR));
  
   //float specDot = max (0.0, dot (vN, vH));
   
   if (difDot > 0) {
      float specPower = pow (specDot, shiness);
      FragColor.rgb += specPower*specularColor.rgb;
   }
   //FragColor.rgb = vLightDir;
}